package com.example;

//import org.javapict.*;
import org.pict.gui.*;

class Begin extends _Process{
	@Override
	public void run(){
		System.out.println("Begin");
		_Channel ch = (_Channel)connections.keySet().toArray()[0];
		_Message msg = new _Message();
		msg.dict.put("Begin msg1", 0);
		this.send(ch, msg);
		_Channel ch2 = (_Channel)connections.keySet().toArray()[1];
		_Message msg2 = new _Message();
		msg2.dict.put("Begin msg2", 1);
		this.send(ch2, msg2);
		System.out.println("Begin END");
	}
}
class Dba_Permission extends _Process{
	@Override
	public void run(){
		System.out.println("Entered : Dba Permission");
		_Channel ch = (_Channel)connections.keySet().toArray()[0];
		_Message msg = new _Message();
		this.receive(ch, msg);
		//System.out.println("Started C");
		_Channel ch2 = (_Channel)connections.keySet().toArray()[1];
		_Message msg2 = new _Message();
		msg2.dict.put("Dba permission msg", 10);
		this.send(ch2, msg2);
		//this.send(ch, msg2);
		System.out.println("Leaving: Dba Permission");
	}
}

class System_Permission extends _Process{
	@Override
	public void run(){
		System.out.println("Entered : System Permission");
		_Channel ch = (_Channel)connections.keySet().toArray()[1];
		_Message msg = new _Message();
		this.receive(ch, msg);
		//System.out.println("Started D");
		_Channel ch2 = (_Channel)connections.keySet().toArray()[0];
		_Message msg2 = new _Message();
		msg2.dict.put("System Permission msg", 20);
		this.send(ch2, msg2);
		System.out.println("Leaving : System Permission");
	}
}
class Cleanup extends _Process{
	@Override
	public void run(){
		System.out.println("Entered : Cleanup");
		_Channel ch = (_Channel)connections.keySet().toArray()[0];
		_Message msg = new _Message();
		this.receive(ch, msg);
		_Channel ch2 = (_Channel)connections.keySet().toArray()[3];
		_Message msg2 = new _Message();
		this.receive(ch2, msg2);
		//if(msg2.dict.get('d') != null || msg2.dict.get('c') != null){
		_Channel ch3 = (_Channel)connections.keySet().toArray()[1];
		_Message msg3 = new _Message();
		msg3.dict.put("Cleanup msg 1", 20);
		this.send(ch3, msg3);
		_Channel ch4 = (_Channel)connections.keySet().toArray()[2];
		_Message msg4 = new _Message();
		msg3.dict.put("Cleanup msg 2", 50);
		this.send(ch4, msg4);
		System.out.println("Leaving : Cleanup");
	}
}

class DatabaseBackup extends _Process{
	@Override
	public void run(){
		System.out.println("Entered : Database Backup");
		_Channel ch = (_Channel)connections.keySet().toArray()[0];
		_Message msg = new _Message();
		this.receive(ch, msg);
		_Channel ch3 = (_Channel)connections.keySet().toArray()[1];
		_Message msg3 = new _Message();
		msg3.dict.put("Database backup", 20);
		this.send(ch3, msg3);
		//System.out.println("Started F");
		System.out.println("Leaving : Database Backup");
		return;
	}
}
class SystemBackup extends _Process{
	@Override
	public void run(){
		System.out.println("Entered : System Backup");
		_Channel ch = (_Channel)connections.keySet().toArray()[0];
		_Message msg = new _Message();
		this.receive(ch, msg);
		_Channel ch3 = (_Channel)connections.keySet().toArray()[1];
		_Message msg3 = new _Message();
		msg3.dict.put("System Backup", 20);
		this.send(ch3, msg3);
		
		//System.out.println("Started F");
		System.out.println("Leaving : System Backup");
		return;
	}
}
class Report extends _Process{
	@Override
	public void run(){
		System.out.println("Entered : Report");
		_Channel ch = (_Channel)connections.keySet().toArray()[0];
		_Message msg = new _Message();
		this.receive(ch, msg);
		//System.out.println("Started E 0");
		_Channel ch2 = (_Channel)connections.keySet().toArray()[1];
		_Message msg2 = new _Message();
		this.receive(ch2, msg2);		
		System.out.println("Leaving : Report");
	}
}

public class WorkFlowTest{
	public static void main(String args[]){
		Begin a = new Begin(); System_Permission b = new System_Permission(); 
		Dba_Permission c = new Dba_Permission(); Cleanup d = new Cleanup(); 
		DatabaseBackup e = new DatabaseBackup(); SystemBackup f = new SystemBackup();
		Report r = new Report();
		_Channel c1 = new _Channel(), c2 = new _Channel(), c3 = new _Channel(), c4 = new _Channel(),
				c5 = new _Channel(), c6 = new _Channel(), c7 = new _Channel(), c8 = new _Channel();
		a.addConnnection(c1, b);
		a.addConnnection(c2, c);
		b.addConnnection(c3, d);
		c.addConnnection(c4, d);
		d.addConnnection(c5, e);
		d.addConnnection(c6, f);
		e.addConnnection(c7, r);
		f.addConnnection(c8, r);
		r.parallel(r, f);
		e.parallel(e, d);
		c.parallel(c, b);
		a.run();
	}
}